<template>
	<view>
		<view class="swiper-container">
			<!-- <up-swiper :list="list1" indicator circular indicatorMode="dot" height="370rpx"></up-swiper> -->
			<swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000" style="height: 370rpx;">
				<swiper-item class="w-100 h-100" v-for="item in state.banner" :key="item.id">
					<image class="w-100 h-100" :src="item.image" mode=""></image>
				</swiper-item>
			</swiper>
		</view>
		<view class="container">
			<view class="container-list">
				<view class="mb28 col3 font32">合伙人工作台</view>
				<!--  申请加入     -->
				<view class="container-list-but font28" v-if="userHh!==1||show">
					<view class="flex flex-between">
						<view>
							<view class="mb20" style="width: 400rpx;">{{iconState.list2[0].iconName}}</view>
							<view class="font24 add-but col-white" @click="handleJoin(1)">申请加入 ></view>
						</view>
						<image :src="iconState.list2[0].icon"></image>
					</view>
				</view>
				<!-- 申请加入后       -->
				<view class="flex flex-between font24 flex-wrap" v-if="userHh===1">
					<view class="icon-list" @click="handleGoto(1,item)" v-for="item in iconState.list1" :key="item.id">
						<up-image class="mb20" :show-loading="true" :src="item.indexIcon" width="68rpx"
							height="68rpx"></up-image>
						<view>{{item.indexInfo}}</view>
					</view>
					<view class="icon-list"></view>
				</view>
				<!-- <up-swiper :list="list1" indicator circular indicatorMode="dot" height="200rpx"></up-swiper> -->
			</view>
			<view class="container-list">
				<view class="mb28 col3 font32">伴宠师工作台</view>
				<!--  申请之前       -->
				<view class="container-list-but" style="background: #FFECE5" v-if="userBcs!==1||show">
					<view class="flex flex-between">
						<view>
							<view class="mb20" style="width: 450rpx;">{{iconState.list2[1].iconName}}</view>
							<!-- <view class="mb20">亲密接触，获得服务报酬</view> -->
							<view class="font24 add-but col-white" style="background: #FF8343" @click="handleJoin(2)">
								申请加入 ></view>
						</view>
						<image :src="iconState.list2[1].icon"></image>
					</view>
				</view>
				<!--  申请之后      -->
				<!-- 申请加入后       -->
				<view class="flex-rowl flex-wrap" v-if="userBcs===1">
					<view class="icon-list" v-for="item in iconState.accompanyData" :key="item.id"
						@click="handleClick(item)">
						<up-image class="mb20" :show-loading="true" :src="item.indexIcon" width="68rpx"
							height="68rpx"></up-image>
						<view>{{ item.indexInfo }}</view>
					</view>
				</view>
			</view>
		</view>
		<ModalCom :open="isoOpen" @close="modalClose" />
	</view>

</template>

<script setup>
	import ModalCom from "./components/modal.vue"
	import {
		onShow
	} from "@dcloudio/uni-app"
	import {
		banner,
		joinHh,
		joiBcs,
		indexConfig,
		indexConfigIco,
		getbaseInfo
	} from "../../api/home.js"
	import {
		onMounted,
		reactive,
		ref
	} from "vue";
	import tab from "../../plugins/tab";
	import {
		getLoginStatus
	} from "../../utils/useMixin";

	const accompanyData = [{
		name: "服务信息",
		code: '1',
		url: ""
	}, {
		name: "服务记录",
		code: '2',
		url: ""
	}, {
		name: "接单地址",
		code: '3',
		url: ""
	}, {
		name: "平台手册",
		code: '4',
		url: ""
	}, {
		name: "我的评价",
		code: '5',
		url: ""
	}]
	const state = reactive({
		banner: []
	})
	onMounted(() => {
		getBanner()
		getpz()
	})
	const userHh = ref(0)
	const userBcs = ref(0)
	onShow(() => {
		const info = uni.getStorageSync("baseInfo")
		if (info) {
			const baseInfo = JSON.parse(info)
			userHh.value = baseInfo.userHh === 1 ? 0 : 1
			userBcs.value = baseInfo.userBcs === 1 ? 0 : 1
			if (userHh.value === 1 || userBcs.value === 1) {
				show.value = false
			}
		}
	})
	// 获取轮播图
	const getBanner = async () => {
		const res = await banner()
		if (res.code === 200) {
			state.banner = [...res.data]
		}
	}
	// 申请加入合伙人
	const num = ref(0)
	const isoOpen = ref(false)
	const handleJoin = (type) => {
		num.value = Number(type)
		const info = uni.getStorageSync("baseInfo")
		if (!info) {
			uni.navigateTo({
				url: "/pages/login/index"
			})
			return
		}
		const baseInfo = JSON.parse(info)
		if (type === 1) {
			joinHh({
				appUserId: baseInfo.userId
			}).then(res => {
				isoOpen.value = true
				changeBaseInfo(baseInfo.userId)
			}).catch(() => {})
		} else {
			joiBcs({
				appUserId: baseInfo.userId
			}).then(res => {
				isoOpen.value = true
				changeBaseInfo(baseInfo.userId)
			})
		}
	}
	// 更新基本信息
	const changeBaseInfo = (userId) => {
		getbaseInfo(userId).then(res => {

		})
	}

	const modalClose = () => {
		isoOpen.value = false
		if (num.value === 1) {
			show.value = false
			userHh.value = 1
		} else {
			show.value = false
			userBcs.value = 1
		}

	}

	// 获取工作台图标
	const iconState = reactive({
		list1: [],
		list2: [],
		accompanyData: []
	})
	const getpz = () => {
		indexConfig().then(res => {
			iconState.list1 = res.rows
		})
		indexConfigIco().then(res => {
			iconState.list2 = res.data
		})

	}

	const show = ref(true)
	const hhShow = ref(true)
	const handleGoto = (val, item) => {
		console.log(item)
		switch (item.id) {
			case 1:
				tab.navigateTo('/otherPages/binding/list/index')
				break;
			case 2:
				tab.navigateTo('/otherPages/workbenchManage/myUser/index')
				break;
			case 3:
				tab.navigateTo('/otherPages/workbenchManage/myLevel/index')
				break;
			case 4:
				// tab.navigateTo('/otherPages/binding/wallet/index')
				tab.navigateTo('/otherPages/workbenchManage/myWallet/index')
				break;
		}
	}
	// 加入合伙人
	const handleAdd = (type) => {
		if (!getLoginStatus()) return
		switch (type) {
			case 1:
				break
			case 2:
				tab.navigateTo("/otherPages/workbenchManage/feedingStaff/index")
				break
		}
	}

	const handleClick = (item) => {
		switch (item.code) {
			case "1":
				uni.navigateTo({
					url: "/otherPages/authentication/serve/index"
				})
				break;
			case "2":
				uni.navigateTo({
					url: "/otherPages/authentication/serve/record"
				})
				break;
			case "3":
				uni.navigateTo({
					url: "/otherPages/authentication/connectAddress/index"
				})
				break;
			case "4":
				break;
			case "5":
				uni.navigateTo({
					url: "/otherPages/orderTakingManage/evaluate/index"
				})
				break;
		}
	}

	const handleOpen = () => {
		show.value = false
	}
	const handleBc = () => {
		uni.navigateTo({
			url: "/otherPages/authentication/list/index"
		})
	}
</script>

<style scoped lang="scss">
	@import "index";
</style>